<template>
  <div class="item" @mouseover="itemOver" @click="changeSelect" @mouseout="itemOut">
    <div class="positionDiv">
      <el-checkbox @click="changeSelect" v-model="mySelect" label=""></el-checkbox>
    </div>
    <img :src="imagePath" :alt="imagePath">
    <div class="info" :class="{'show':show}">
      <slot/>
    </div>
  </div>
</template>

<script setup lang="ts">
import {computed} from "vue";

const props = defineProps({
  show: {
    type: Boolean,
    default: false
  },
  checkedFlag: {
    type: Boolean,
    default: false
  },
  imagePath: {
    type: String,
    default: ''
  },
  itemWidth: {
    type: String,
    default: '250px'
  }
});

const mySelect = computed({
  get() {
    return props.checkedFlag;
  },
  set() {
    changeSelect()
  },
});

interface IEmitsType {
  (e: 'update:show', show: boolean): void;

  (e: 'update:checkedFlag', show: boolean): void;
}

const emit = defineEmits<IEmitsType>();

const itemOver = () => {
  emit('update:show', true)
}
const itemOut = () => {
  emit('update:show', false)
}

// 设置选择的item
const changeSelect = () => {
  emit('update:checkedFlag', !props.checkedFlag)
}

</script>

<style lang="scss" scoped>
//可以使用栅格系统
$video-item-width: v-bind('props.itemWidth');

div.item {
  width: $video-item-width;
  height: 200px;
  margin: 5px;
  background: #373738;
  display: flex;
  justify-content: center;
  align-content: center;
  cursor: pointer;
  position: relative;

  .positionDiv {
    position: absolute;
    left: 8px;
  }

  & > img {
    max-width: $video-item-width;
    max-height: 200px;
    margin: auto;
  }

  .info {
    position: absolute;
    width: $video-item-width;
    height: 30px;
    background: rgba(71, 75, 71, 0.8);
    margin-top: 170px;
    color: #ffffff;
    font-size: 14px;
    display: flex;
    justify-content: flex-start;
    align-content: center;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s;

    ::v-deep(span) {
      padding-left: 5px;

    }

    &.show {
      height: 100px;
      margin-top: 100px;
    }
  }
}
</style>
